package zhai.docking.alipay.util;

import com.alibaba.fastjson.JSON;

import java.util.List;

/**
 * @package: zhai.docking.alipay.util
 * @project-name: zhai-docking-alipay
 * @description: JSON工具类
 * @author: Created by 翟凤玺
 * @create-datetime: 2018-7-10 17:26
 */
public class JSONUtil {

    /**
     * 对象转JSON字符串
     */
    public static String toStr(Object object) {
        return JSON.toJSONString(object);
    }

    /**
     * 字符串转对象
     */
    public static <T> T toObj(String json, Class<T> clazz) {
        return JSON.parseObject(json, clazz);
    }

    /**
     * 字符串转数组对象
     */
    public static <T> List<T> toArr(String json, Class<T> clazz) {
       return JSON.parseArray(json, clazz);
    }
}
